import { getThsNews } from '@/server/controllers/articleController';
import { format } from 'date-fns';
import Link from 'next/link';

const NewsPage = async ({ params }) => {
    const { secuCode } = await params;
    const news = await getThsNews(secuCode);
    const todayStr = format(new Date(), 'MM-dd');
    return (
        <div className="h-full w-full">
            {news.map((item) => (
                <div
                    style={{
                        color: `${item.newsTime.includes(todayStr) ? 'cyan' : 'yellow'}`,
                        borderBottom: '1px solid #ccc',
                        fontSize: '0.4rem'
                    }}
                    key={item.newsId}
                >
                    <Link href={`${item.newsUrl}`} target="_blank">
                        <span
                            style={{
                                display: 'block',
                                color: `${item.newsUrl.includes('weixin.qq.com') ? 'red' : null}`,
                                overflow: 'hidden',
                                textOverflow: 'ellipsis',
                                whiteSpace: 'nowrap',
                                width: '100%'
                            }}
                        >
                            {item.newsTime}|{item.newsTitle}
                        </span>
                    </Link>
                </div>
            ))}
        </div>
    );
};

export default NewsPage;
